package main.aquarium

//在Kotlin的代码中一般只需要一个构造函数和一个init块，对于函数的重载可以使用默认参数来实现
class Fish(val friendly: Boolean, volumeNeeded: Int) {
    val size: Int

    init {
        println("first init block")
    }

    constructor() : this(true, 9) {
        println("running secondary constructor")
    }

    init {
        size = if (friendly) {
            volumeNeeded
        } else {
            volumeNeeded * 2
        }
    }

    init {
        println("constructed fish of size $volumeNeeded, final size is $size")
    }

    init {
        println("last init block")
    }
}

fun makeDefaultFish() = Fish(true, 50)

fun printFishExample() {
    val fish = Fish(true, 20)
    println("this fish is friendly ${fish.friendly}, it needs volume ${fish.size}")
}

fun main() {
    printFishExample()
}